import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class CalculatorTest {
	private static Calculator calculator = new Calculator();


	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testAdd() {
		calculator.clear();
		calculator.add(2);
		calculator.add(4);		
		assertEquals(6,calculator.getResult());

	}

	@Test
	public void testSubtract() {
		calculator.clear();
		calculator.add(10);
		calculator.subtract(2);
		assertEquals(8,calculator.getResult());

	}

	@Test
	public void testMultiply() {
		calculator.clear();
		calculator.add(10);
		calculator.multiply(2);;
		assertEquals(20,calculator.getResult());

	}

	@Test
	public void testDivide() {
		calculator.clear();
		calculator.add(10);
		calculator.divide(2);
		assertEquals(5,calculator.getResult());

	}

	@Test
	public void testSquare() {
		calculator.clear();
		calculator.square(3);
		assertEquals(9,calculator.getResult());

	}

	@Test(timeout=1000)
	public void testSquareRoot() {
		calculator.clear();
		calculator.squareRoot(16);
		assertEquals(4,calculator.getResult());

	}
	@Test(expected = ArithmeticException.class)

	public void divideByZero(){
		calculator.clear();
		calculator.divide(0);
	}


}
